<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Paymentaccounts extends CI_Controller {

	var $userId = 0;
	
	public function index()
	{
		$this->load->view('v_paymentaccounts');
	}
	
	public function deleteaccount($accountId)
	{
		$this->load->model('m_paymentaccounts', 'deleteaccount');
		$this->deleteaccount->set_user_id($this->getId());
		$this->deleteaccount->set_account_id($accountId);
		//var_dump($this->deleteaccount);
		$this->deleteaccount->delete_payment_account();
		$this->load->view('v_paymentaccounts');
	}
	
	public function editaccount($accountId)
	{
		$this->load->model('m_paymentaccounts', 'editaccount');
		$this->editaccount->set_user_id($this->getId());
		$this->editaccount->set_account_name($_POST['name']);
		$this->editaccount->set_account_type($_POST['type']);
		$this->editaccount->set_account_number($_POST['number']);
		$this->editaccount->set_account_id($accountId);
		//var_dump($this->editaccount);
		$this->editaccount->edit_payment_account();
		$this->load->view('v_paymentaccounts');
	}

	public function addaccount()
	{
		$this->load->model('m_paymentaccounts', 'newAccount');
		$this->newAccount->set_user_id($this->getId());
		$this->newAccount->set_account_name($_POST['name']);
		$this->newAccount->set_account_type($_POST['type']);
		$this->newAccount->set_account_number($_POST['number']);

		$this->newAccount->edit_payment_account();
		$this->load->view('v_paymentaccounts');
	}

	function getId()
	{
		if($this->userId == 0)
		{
			$this->load->model('m_user', 'currentUser');
			$this->currentUser->set_user_email($this->session->userdata('useremail'));
			$this->userId = $this->currentUser->get_user_id();
		}
		return $this->userId;
	}

	public function getpaymentaccounts()
	{
		$this->load->model('m_paymentaccounts', 'payment');
		$json = $this->payment->get_payment_accounts($this->getId());
		$jsonObject = json_decode($json);

		$aaData = array();
		
		foreach($jsonObject->aaData as $row)
		{
			$accountId = $row['3'];
			$row['3']  = '<a class="btn" href="' . site_url("editpaymentaccount/index/" . $accountId) . '">View/Change</a> | ';
			$row['3'] .= '<a class="btn" href="' . site_url("confirmdeletepaymentaccount/index/" . $accountId) . '">Delete</a>';
			array_push($aaData, $row); 
		}
		
		$jsonObject->aaData = $aaData;
		
		echo json_encode($jsonObject);
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */